package pwd.allen.androiddemo.activity;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.Date;

import pwd.allen.androiddemo.R;
import pwd.allen.androiddemo.util.ToastUtil;

public class DialogActivity extends AppCompatActivity implements View.OnClickListener, DialogInterface.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        findViewById(R.id.button).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        new AlertDialog.Builder(this)
                .setIcon(R.mipmap.ic_launcher)
                .setTitle("对话框标题")
                .setMessage(String.format("现在时间是：%s", new Date()))
                .setPositiveButton("确定", this)
                .setNegativeButton("取消", this)
                .setNeutralButton("中间按钮", this)
                .create()
                .show();

        // TODO setView设置自定义布局
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case Dialog.BUTTON_POSITIVE:
                ToastUtil.show(this, "点击了确定按钮");
                break;
            case Dialog.BUTTON_NEGATIVE:
                ToastUtil.show(this, "点击了取消按钮");
                break;
            case Dialog.BUTTON_NEUTRAL:
                ToastUtil.show(this, "点击了中性按钮");
                break;
        }
    }
}
